
namespace StringHelper
{
    inline int ToInteger(const string &s)
    {
        return atoi(s.c_str());
    }

    inline UINT ToUnsignedInteger(const string &s)
    {
        return UINT(atoi(s.c_str()));
    }

    inline float ToFloat(const string &s)
    {
        return float(atof(s.c_str()));
    }

    inline double ToDouble(const string &s)
    {
        return atof(s.c_str());
    }

    inline bool StartsWith(const string &s, const char *startCandidate)
    {
        for(UINT charIndex = 0; charIndex <= s.size(); charIndex++)
        {
            char c = startCandidate[charIndex];
            if(c == 0)
            {
                return true;
            }
            else if(c != s[charIndex])
            {
                return false;
            }
        }
        return false;
    }

    inline bool StartsWith(const string &s, const string &startCandidate)
    {
        if(s.size() < startCandidate.size())
        {
            return false;
        }
        for(UINT charIndex = 0; charIndex <= startCandidate.size(); charIndex++)
        {
            if(s[charIndex] != startCandidate[charIndex])
            {
                return false;
            }
        }
        return true;
    }

    inline vector<string> Partition(const string &s, const string &separator)
    {
        vector<string> result;
        string curEntry;
        const UINT size = s.size();
        for(UINT charIndex = 0; charIndex < size; charIndex++)
        {
            bool isSeparator = true;
            for(UINT testIndex = 0; testIndex < separator.size() && charIndex + testIndex < size && isSeparator; testIndex++)
            {
                if(s[charIndex + testIndex] != separator[testIndex])
                {
                    isSeparator = false;
                }
            }

            if(isSeparator)
            {
                if(curEntry.size() > 0)
                {
                    result.push_back(curEntry);
                    curEntry.clear();
                }
                charIndex += separator.size() - 1;
            }
            else
            {
                curEntry.push_back(s[charIndex]);
            }
        }
        if(curEntry.size() > 0)
        {
            result.push_back(curEntry);
        }
        return result;
    }
};
